//
//  GYCategoryViewModel.m
//  GYDemo
//
//  Created by Mrzhang on 2018/3/27.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "GYCategoryViewModel.h"
#import "Head.h"

@implementation GYNewGoodListModel
@end
@implementation GYCategoryViewModel
#pragma mark - getter and setter
-(NSMutableArray *)datas
{
    if (!_datas) {
        _datas = [NSMutableArray new];
    }
    return _datas;
}
-(instancetype)init
{
    if (self = [super init]) {
        //添加接口特殊处理
        [[InterfaceManager shareInterface].specialInterfaces addObject:@"productDetail"];
    }
    return self;
}

#pragma mark - method
-(void)requestDatas:(NSMutableDictionary *)para
{
    @WeakSelf;
    NSString *interface = @"productDetail";
    NSString *page = para[@"page"];
    [[InterfaceManager shareInterface]requetInterface:interface withParameter:para handler:^(NSDictionary *info, InterfaceStatusModel *infoModel) {
        NSDictionary *data = infoModel.data;
        if ([data isKindOfClass:[NSDictionary class]]) {
            NSArray *datalist = data[@"datalist"];
            
            if ([datalist count]<10) {
                selfp.canAddMore=NO;
            }else
            {
                selfp.canAddMore=YES;
            }
            if ([datalist isKindOfClass:[NSArray class]]) {
                NSMutableArray *arr;
                if ([page isEqualToString:@"1"]) {
                    arr = [NSMutableArray new];
                }else{
                    arr = _datas;
                }
                for (NSDictionary *dic in datalist) {
                    GYNewGoodListModel *model = [GYNewGoodListModel yy_modelWithJSON:dic];
                    [arr addObject:model];
                }
                [selfp setDatas:arr];
                [selfp setTotalCount:[data objectForKey:@"total"]];
            }
        }else
        {
            selfp.canAddMore=NO;

            if ([page isEqualToString:@"1"])
            {
                NSMutableArray *arr;
                [selfp setDatas:arr];
                [selfp setTotalCount:@"0"];
            }

        }
    }];
}

@end
